//
//  KTHttpTool.swift
//  KTDouYu
//
//  Created by CoolKi on 16/5/5.
//  Copyright © 2016年 CoolKi. All rights reserved.
//

import UIKit
import AFNetworking

class KTHttpTool: AFHTTPSessionManager {

    // // 创建请求管理者
    static let shareInstance : KTHttpTool = {
        let tool = KTHttpTool()
        let set = NSSet(objects: "text/html","application/json","text/json", "text/javascript","text/css")
        for strSet in set {
            tool.responseSerializer.acceptableContentTypes?.insert(strSet as! String)
        }
        return tool
    }()

    

    func KT_GET(urlString : String,parameters : AnyObject?,success : (dataTask:NSURLSessionDataTask, response:AnyObject?)->(),faifure : (dataTask : NSURLSessionDataTask?, error : NSError)->()) -> (){
        GET(urlString, parameters: parameters, progress: nil, success: { (dataTask:NSURLSessionDataTask, response:AnyObject?) -> Void in
            //print(response)
            success(dataTask: dataTask, response: response)
            }) { (dataTask : NSURLSessionDataTask?, error : NSError) -> Void in
                faifure(dataTask: dataTask, error: error)
        }
    }
    
    
    func KT_POST(urlString : String,paramater : AnyObject?,success : (dataTask:NSURLSessionDataTask, response:AnyObject?)->(),failure : (dataTask : NSURLSessionDataTask?, error : NSError)->()) -> (){

        POST(urlString, parameters: paramater, progress: nil, success: { (dataTask:NSURLSessionDataTask, response : AnyObject?) -> Void in
            success(dataTask: dataTask, response: response)
            }) { (dataTask : NSURLSessionDataTask?,error : NSError) -> Void in
                failure(dataTask: dataTask, error: error)
        }
    }
    
    
    
}








